/*
 * @Description:
 * @Author: Rfan
 * @Date: 2023-01-04 21:04:56
 * @LastEditTime: 2023-01-06 20:46:02
 */

import TitleProps from './parts/TitleProps';

const LOW_PRIORITY = 500;

function createReviewerTabGroups(element, translate) {
  const reviewerGroup = {
    id: 'editReviewer',
    label: translate('审批'),
    entries: []
  };

  TitleProps(reviewerGroup, element, translate);

  return [reviewerGroup];
}

/**
 * A provider with a `#getTabs(element)` method
 * that exposes tabs for a diagram element.
 *
 * @param {PropertiesPanel} propertiesPanel
 * @param {Function} translate
 */
function ReviewerPropertiesProvider(propertiesPanel, translate) {
  /**
   * Return the tabs provided for the given element.
   *
   * @param {DiagramElement} element
   *
   * @return {(Object[]) => (Object[])} tab entry middleware
   */
  this.getTabs = function (element) {
    /**
     * We return a middleware that modifies
     * the existing tabs.
     *
     * @param {Object[]} entries
     *
     * @return {Object[]} modified entries
     */
    return function (entries) {
      const reviewerTab = {
        id: 'reviewer',
        label: '审批',
        groups: createReviewerTabGroups(element, translate)
      };

      entries.push(reviewerTab);

      return entries;
    };
  };

  propertiesPanel.registerProvider(LOW_PRIORITY, this);
}

export default ReviewerPropertiesProvider;

ReviewerPropertiesProvider.$inject = ['propertiesPanel', 'translate'];
